package com.app.web.controller;

import java.io.PrintWriter;
import java.util.List;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.validation.groups.Default;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.app.biz.BackendUserBiz;
import com.app.biz.DevUserBiz;
import com.app.entity.BackendUser;
import com.app.entity.DevUser;


@Controller
public class LoginRegisterController {
	@Autowired
	private DevUserBiz devUserbiz;
	@Autowired
	private BackendUserBiz backendUserBiz;
	
	@RequestMapping("default")
	public String default1(){//默认执行页面
		return "default";
	}
    
	@RequestMapping("/devlogin")
	public String devlogin(Model model){	//跳转测试员登录页面
	    
		return "devlogin";//return "redirect:index";重定向
	}
	@RequestMapping("/backendlogin")
	public String backendlogin(Model model){	//跳转管理员登录页面
	    
		return "backendlogin";//return "redirect:index";重定向
	}
	@RequestMapping("/dobacklogin")
	public String dobacklogin(Model model,HttpSession session,BackendUser backendUser){//验证用户跟密码登录
		//管理员登录
		if(backendUser!=null){
					BackendUser backendUser2=backendUserBiz.checkBackUserLogin(backendUser.getUserName(), backendUser.getUserPassword());
					if(backendUser2!=null){
						session.setAttribute("backendUser",backendUser2);
						System.out.println(backendUser2.getUserName());
					}	  	
		}
		return "redirect:backindex";
	}
	@RequestMapping("/dodevlogin")
	public String dodevlogin(Model model,HttpSession session,DevUser devUser){
		//测试员登录
				if(devUser!=null){
					//System.out.println("进来1");
					DevUser devUser2=devUserbiz.checkDevUserLogin(devUser.getDevName(), devUser.getDevPassword());
					if(devUser2!=null){
						//System.out.println("进来2");
						session.setAttribute("devUser",devUser2);
						System.out.println(devUser2.getDevName());
					}
				}
		 return "redirect:index";	
	}
	
}
